import logging

from requests import Session

from config import HOST


class RegisterAPI:
    def __init__(self, session: Session):
        self.__session = session

    def captcha_code_api(self, random: str):
        logging.info(F"图片验证码请求接口 / 请求方法: get / 请求url: {HOST}/common/public/verifycode1/{str(random)}")
        return self.__session.get(HOST + F"/common/public/verifycode1/{str(random)}")

    def phone_code_api(self, phone: str, captcha: str):
        data = {"phone": phone, "imgVerifyCode": captcha, "type": "reg"}
        logging.info(F"短信验证码请求接口 / 请求方法: post / 请求url: {HOST}/member/public/sendSms / 请求数据: {data}")
        return self.__session.post(HOST + "/member/public/sendSms", data)

    def register_api(self, phone: str, pwd: str, captcha: str, phone_code: str, invite_phone: str):

        data = {"phone": phone, "password": pwd, "verifycode": captcha, "phone_code": phone_code,
                "dy_server": "on", "invite_phone": invite_phone}
        logging.info(
            F"注册接口 / 请求方法: post / 请求url: {HOST}/member/public/reg / 请求数据: {data}")
        return self.__session.post(HOST + "/member/public/reg", data=data)

